//
//  SLBaseViewModel.m
//  Objective-C
//
//  Created by S_Line on 2018/9/4.
//  Copyright © 2018年 S_Line. All rights reserved.
//

#import "SLBaseViewModel.h"

@interface SLBaseViewModel()

@end

@implementation SLBaseViewModel

- (instancetype)init {
    self = [super init];
    
    if (self) {
        self.sections = [NSMutableArray new];
        self.dataDict = [NSMutableDictionary new];
        [self initData];
    }
    
    return self;
}

- (void)initData {
    
}

- (NSInteger)numberOfSections {
    return self.sections.count;
}

- (NSInteger)numberOfRowsInSection:(NSInteger)section {
    if (section >= self.sections.count) {
        return 0;
    }
    
    NSString *sectionName = self.sections[section];
    NSArray *dataArray = self.dataDict[sectionName];
    if (!dataArray || ![dataArray isKindOfClass:[NSArray class]]) {
        return 0;
    }
    
    return dataArray.count;
}

- (id)dataForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section >= self.sections.count) {
        return nil;
    }
    
    NSString *sectionName = self.sections[indexPath.section];
    NSArray *dataArray = self.dataDict[sectionName];
    if (!dataArray || ![dataArray isKindOfClass:[NSArray class]] || indexPath.row >= dataArray.count) {
        return nil;
    }
    return dataArray[indexPath.row];
}

- (id)dataForSection:(NSInteger)section {
    if (section >= self.sections.count) {
        return nil;
    }
    
    return self.sections[section];
}

@end
